package Demo6;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 洪汤泽大帅哥
 * Date: 2024-12-19
 * Time: 21:39
 */
import java.util.Scanner;
public class Main {
    public static void main(String args[]){
        Scanner scan=new Scanner(System.in);
        int oldArr[]=new int[10];
        int newArr[];
        for(int i=0;i<oldArr.length;i++)
            oldArr[i]=scan.nextInt();
        int n=count(oldArr);
        newArr=new int[n];
        create(oldArr,newArr);
        for(int i=0;i<newArr.length;i++)
            System.out.print(newArr[i]+" ");
    }
    //统计数组中不等于0的个数
    public static int count(int a[]){
        int n = 0;
        for (int i = 0; i < a.length; i++) {
            if (a[i]!=0){
                n++;
            }
        }
        return n;
    }
    //将不等于0的数产生一个新的数组
    public static void create(int a[],int b[]){
        int i = 0;
        int j = 0;
        while (i<a.length){
            if (a[i]!=0){
                b[j] = a[i];
                j++;
                i++;
            }
            else {
                i++;
            }
        }

    }
}

